<?php
    class ReplacesController extends AppController {
        var $name = 'Replace';
        var $components = array('Session');

        function index() {
            $this->set('rep', $this->Replace->find('all')); 
		/*	// Add filter
			$this->Filter->addFilters(
				array(
					'filter1' => array(
						'Replace.comments' => array(
							'operator' => 'LIKE',
							'value' => array(
								'before' => '%', // optional
								'after'  => '%'  // optional
							)
						)
					)
				)
			);

			$this->Filter->setPaginate('order', 'Replace.comments ASC'); // optional
			$this->Filter->setPaginate('limit', 10);              // optional

			// Define conditions
			$this->Filter->setPaginate('conditions', $this->Filter->getConditions());

			$this->Replace->recursive = 0;
			$this->set('replaces', $this->paginate());*/
        }

        function view($id) {
            $this->Replace->id = $id;
            $this->set('post', $this->Replace->read());

        }

        function add() {
            if (!empty($this->data)) {
                if ($this->Replace->save($this->data)) {
                    $this->Session->setFlash('Your data has been saved.');
                    $this->redirect(array('action' => 'index'));
                }
				else {
					$this->Session->setFlash('The post was not saved... Please try again!');
				}
            }
        }
		
		public function delete($id) {
		   if ($this->request->is('post')) {
			if ($this->Replace->delete($id)) {
			  $this->Session->setFlash(__('The post number %s has been deleted.', h($id)));
			  return $this->redirect(array('action' => 'index'));
			}
		  }
		}

		public function edit($id = null) {
    if (!$id) {
        throw new NotFoundException(__('Post is not valid!'));
    }
    $repl = $this->Replace->findById($id);
    if (!$repl) {
        throw new NotFoundException(__('Post is not valid!'));
    }
	
    if ($this->request->is('post') || $this->request->is('put')) {
        $this->Replace->id = $id;		
        $post_data = $this->request->data;
        if ($this->Replace->save($post_data)) {
            $this->Session->setFlash(__('Your post has been updated.'));
            return $this->redirect(array('action' => 'index'));
        }
        $this->Session->setFlash(__('Unable to update your post.'));
    }

    if (!$this->request->data) {
        $this->request->data = $repl;
    }
}

 
    }

?>